package com.teradata.olingo.processor.core.api;

import com.teradata.olingo.processor.core.exception.ODataGenericProcessException;
import com.teradata.olingo.processor.core.modify.GenericUpdateResult;
import com.teradata.olingo.processor.core.processor.GenericRequestEntity;
import org.apache.olingo.commons.api.http.HttpMethod;


public interface GenericCUDRequestHandler {
  /**
   * 
   * @param requestEntity
   * @throws ODataGenericProcessException
   */
  public void deleteEntity(final GenericRequestEntity requestEntity)
      throws ODataGenericProcessException;

  /**
   * Hook to create an entity. Transaction handling is done outside to guarantee transactional behavior of change
   * sets in batch requests. This method has to return the newly create entity even so validateChanges is implemented.
   * 
   * @param et Metadata about the entity type that shall be created
   * @param jpaAttributes List of attributes with pojo attributes name and converted into JAVA types
   * @param em Instance of an entity manager.
   * @return The newly created instance or map of created attributes including default and added values
   * following the same rules as jpaAttributes
   * @throws ODataGenericProcessException
   */

  /**
   * 
   * @param requestEntity
   * @return The newly created instance or map of created attributes including default and added values
   * following the same rules as jpaAttributes
   * @throws ODataGenericProcessException
   */
  public Object createEntity(final GenericRequestEntity requestEntity)
      throws ODataGenericProcessException;

  /**
   * <a href=
   * "http://docs.oasis-open.org/odata/odata/v4.0/errata03/os/complete/part1-protocol/odata-v4.0-errata03-os-part1-protocol-complete.html#_Toc453752300"
   * >OData Version 4.0 Part 1 - 11.4.3 Update an Entity</a>
   * @param requestEntity
   * @param httpMethod
   * @return The response describes the performed changes (Created or Updated) as well as the result of the operation.
   * It must not be null. Even if nothing was changed => update is idempotent
   * @throws ODataGenericProcessException
   */
  public GenericUpdateResult updateEntity(final GenericRequestEntity requestEntity,
                                          final HttpMethod httpMethod) throws ODataGenericProcessException;

  /**
   * Hook that is called if all changes of one transaction have been processed. The method shall enable a check all
   * modification within the new context. This can be imported if multiple entities are changes with the same request
   * (batch request or deep-insert) and consistency constrains exist between them.
   * @throws ODataGenericProcessException
   */
  public void validateChanges() throws ODataGenericProcessException;
}
